﻿/*
 * Created by SharpDevelop.
 * User: dol
 * Date: 16/6/2556
 * Time: 6:42
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace titi.utilcanvas
{
	/// <summary>
	/// Description of Class1.
	/// REF CODE is
	/// http://stackoverflow.com/questions/753132/how-do-i-get-the-colour-of-a-pixel-at-x-y-using-c
	/// </summary>
	sealed class SceenPixel
	{
	  [DllImport("user32.dll")]
	  static extern IntPtr GetDC(IntPtr hwnd);
	
	  [DllImport("user32.dll")]
	  static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
	
	  [DllImport("gdi32.dll")]
	  static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
	
	  static public System.Drawing.Color GetPixelColor(int x, int y)
	  {
	   IntPtr hdc = GetDC(IntPtr.Zero);
	   uint pixel = GetPixel(hdc, x, y);
	   ReleaseDC(IntPtr.Zero, hdc);
	   Color color = Color.FromArgb((int)(pixel & 0x000000FF),
	                (int)(pixel & 0x0000FF00) >> 8,
	                (int)(pixel & 0x00FF0000) >> 16);
	   return color;
	  }
	  static public System.Drawing.Color GetPixelColor(System.Drawing.Point pt )
	  {
	  	System.Drawing.Color c = GetPixelColor(pt.X,pt.Y);
	  	return c;
	  }
	}
	
}



